package com.zrt.bookstore3.Controller;


import com.zrt.bookstore3.Domain.SMSCode;
import com.zrt.bookstore3.Service.SMSCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/sms")
public class SMSCodeController {

    @Autowired
    private SMSCodeService smsCodeService;

    @RequestMapping(value = "/getCode",method = {RequestMethod.POST, RequestMethod.GET})
    public String getCode(HttpServletRequest request){
//        System.out.println("哈哈哈哈............");
        String email = request.getParameter("email");
        String telephone = request.getParameter("telephone");
//        System.out.println(email+"..............................");
        //发送人
        String from = "gy20_24jsjxynum1@163.com";
        String code = smsCodeService.sendCodeToSMS(telephone);

        smsCodeService.sendMail(from,email,"验证码",code);

        return "redirect:/pages/registered.html";
    }

    @PostMapping("/checkCode")
    public boolean checkCode(SMSCode smsCode){
        return smsCodeService.checkCode(smsCode);
    }


}
